package com.example.pinkcat.activity.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;

import java.util.ArrayList;


public class VIP_recyleview_adapter extends RecyclerView.Adapter<VIP_recyleview_adapter.ViewHolder>{
    private final Context context;
    int pl_numbers;
    TextView fainalmoney;
    ArrayList<String> moneylist=new ArrayList<>();
    ImageView getimageView;
    int select=0;

    //构造方法
    public VIP_recyleview_adapter(Context context, int pl_numbers,TextView fainalmoney,ImageView getimageView){
        this.context=context;
        this.pl_numbers=pl_numbers;
        this.fainalmoney=fainalmoney;
        this.getimageView=getimageView;
        this.moneylist.add("1 元");
        this.moneylist.add("20 元");
        this.moneylist.add("60 元");
        this.moneylist.add("999 元");
    }

    //内部内
    public static class ViewHolder extends RecyclerView.ViewHolder{
        View vipbtn;
        TextView vipname;
        TextView vipmoney;
        TextView vipoutmoney;

        //寻找声明布局控件
        public ViewHolder(View view) {
            super(view);
            vipbtn=view.findViewById(R.id.viplayout);
             vipname=view.findViewById(R.id.vip_name);
             vipmoney=view.findViewById(R.id.vip_money);
             vipoutmoney=view.findViewById(R.id.vip_out_money);
        }
    }
    //创建获取 view  布局
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //获取item内容
        View view;
        view= LayoutInflater.from(context).inflate(R.layout.list_vip,parent,false);
        return new ViewHolder(view);
    }

    //绑定数据
    @SuppressLint({"CheckResult", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.vipbtn.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_white));
        if (position==select){
            holder.vipbtn.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_grey));
        }
        switch (position){
            case 0:holder.vipname.setText("一天大会员");holder.vipmoney.setText("1 元");holder.vipoutmoney.setText("2 元");break;
            case 1:holder.vipname.setText("月度大会员");holder.vipmoney.setText("20 元");holder.vipoutmoney.setText("30 元");break;
            case 2:holder.vipname.setText("年度大会员");holder.vipmoney.setText("60 元");holder.vipoutmoney.setText("120 元");break;
            case 3:holder.vipname.setText("永久大会员");holder.vipmoney.setText("999 元");holder.vipoutmoney.setText("9999 元");break;
            default:break;
        }
        holder.vipbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"已选择套餐",Toast.LENGTH_SHORT).show();
                fainalmoney.setText(moneylist.get(position));
                switch (position){
                    case 0:getimageView.setImageResource(R.mipmap.v_1yuan);break;
                    case 1:getimageView.setImageResource(R.mipmap.v_20yuan);break;
                    case 2:getimageView.setImageResource(R.mipmap.v_60);break;
                    case 3:getimageView.setImageResource(R.mipmap.v_999yuan);break;
                    default:break;
                }
                select=position;
                notifyDataSetChanged();
            }
        });

    }

    @Override
    public int getItemCount() {
        return pl_numbers;
    }


    @Override
    public int getItemViewType(int position) {
        if (position==0){
            return 0;
        }else {
            return 1;
        }
    }
}
